import { BaseWindow } from "../../../component/window/BaseWindow";
import { IMarketSeekBuyWindow } from "../../../../modules/interfaces/IMarketSeekBuyWindow";
import { ILayer } from "../../../mvc/interfaces/ILayer";
import { Language } from "../../../../extend/language/Language";
import { GTabBar } from "../../../../com/mui/controls/GTabBar";
import { FilterConst } from "../../../component/gconst/FilterConst";
import { MuiEvent } from "../../../../com/mui/events/MuiEvent";
import { SeekBuyItemPanel } from "./SeekBuyItemPanel";
import { QuickSellGoodsPanel } from "./QuickSellGoodsPanel";
import { SelfGoodsPanel } from "./SelfGoodsPanel";
import { SeekBuyGoodsPanel } from "./SeekBuyGoodsPanel";
import { EventName } from "../../mvc/EventName";
import { Dispatcher } from "../../../mvc/core/Dispatcher";
import { DataEvent } from "../../events/DataEvent";
import { Cache } from "../../cache/Cache";
import { SSeqMarketItem } from "../../../../Message/Game/SSeqMarketItem";
import { SellGoodsTips } from "./SellGoodsTips";
type int = number;
//class MarketSeekBuyWindow
    
    export  class MarketSeekBuyWindow extends BaseWindow implements IMarketSeekBuyWindow
    {
        constructor(arg1: ILayer=null)
        {
            super(arg1);
            setSize(322, 402);
            title = Language.getString(31077);
            return;
        }

        protected /* override */ createChildren(): void
        {
            super.createChildren();
            this._tabBar = new GTabBar();
            this._tabBar.x = 16;
            this._tabBar.y = 34;
            this._tabBar.horizontalGap = 2;
            this._tabBar.buttonWidth = 70;
            this._tabBar.buttonFilters = [FilterConst.glowFilter];
            this._tabBar.dataProvider = new Array<any>({"name":"sell", "label": Language.getString(31078)}, {"name":"myGoods", "label": Language.getString(31079)}, {"name":"seekBuy", "label": Language.getString(31080)});
            this._tabBar.selectedIndex = 0;
            this._tabBar.addEventListener(MuiEvent.GTABBAR_SELECTED_CHANGE, this.onTabBarSelectedChangeHandler);
            addChild(this._tabBar);
            this._seekBuyItemPanel = new SeekBuyItemPanel();
            this._seekBuyItemPanel.layer = this;
            return;
        }

        /* internal  */addQuickSellGoodsPanel(): void
        {
            if (this._quickSellGoods == null) 
            {
                this._quickSellGoods = new QuickSellGoodsPanel();
                this._quickSellGoods.x = 18;
                this._quickSellGoods.y = 60;
            }
            addChild(this._quickSellGoods);
            return;
        }

        /* internal  */addSelfGoodsPanel(): void
        {
            if (this._selfGoods == null) 
            {
                this._selfGoods = new SelfGoodsPanel();
                this._selfGoods.x = 18;
                this._selfGoods.y = 60;
                this._selfGoods.setPanel();
            }
            addChild(this._selfGoods);
            return;
        }

        /* internal  */addSeekBuyGoods(): void
        {
            if (this._seekBuyGoods == null) 
            {
                this._seekBuyGoods = new SeekBuyGoodsPanel();
                this._seekBuyGoods.x = 18;
                this._seekBuyGoods.y = 60;
                this._seekBuyGoods.addEventListener(EventName.MarketFilterItemsResult, this.onItemsResultHandler);
            }
            addChild(this._seekBuyGoods);
            return;
        }

        /* internal  */removePanel(): void
        {
            if (this._quickSellGoods && this._quickSellGoods.parent) 
            {
                removeChild(this._quickSellGoods);
            }
            else if (this._selfGoods && this._selfGoods.parent) 
            {
                removeChild(this._selfGoods);
            }
            else if (this._seekBuyGoods && this._seekBuyGoods.parent) 
            {
                removeChild(this._seekBuyGoods);
            }
            return;
        }

        /* internal  */onTabBarSelectedChangeHandler(arg1: MuiEvent): void
        {
            this.tabBarChange();
            return;
        }

        public updatePanel(arg1: int): void
        {
            this._tabBar.selectedIndex = arg1;
            this.tabBarChange();
            return;
        }

        /* internal  */tabBarChange(): void
        {
            this.removePanel();
            var loc1=this._tabBar.selectedIndex;
            switch (loc1) 
            {
                case 0:
                {
                    this.addQuickSellGoodsPanel();
                    this._quickSellGoods.resetPanel();
                    this.hideSeekBuyItem();
                    Dispatcher.dispatchEvent(new DataEvent(EventName.MarketSeekBuyWindowStateChange, true));
                    break;
                }
                case 1:
                {
                    this.addSelfGoodsPanel();
                    this.updateMySeekBuyPanel(true);
                    this.hideSeekBuyItem();
                    Dispatcher.dispatchEvent(new DataEvent(EventName.MarketSeekBuyWindowStateChange, false));
                    break;
                }
                case 2:
                {
                    this.addSeekBuyGoods();
                    this._seekBuyGoods.reset();
                    this._seekBuyGoods.show();
                    this._seekBuyItemPanel.show(332, 1);
                    Dispatcher.dispatchEvent(new DataEvent(EventName.MarketSeekBuyWindowStateChange, false));
                    break;
                }
            }
            return;
        }

        /* internal  */hideSeekBuyItem(): void
        {
            this._seekBuyItemPanel.hide();
            return;
        }

        public updateMySeekBuyPanel(arg1: Boolean=false): void
        {
            if (arg1) 
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.MarketGetSelfSeekBuy));
            }
            if (this._selfGoods && this._selfGoods.parent && Cache.instance.market.sSeqMarketItemSeek) 
            {
                this._selfGoods.updateDataProvider(Cache.instance.market.sSeqMarketItemSeek.marketItems);
            }
            return;
        }

        public updateQuickSellGoodsPanel(arg1: SSeqMarketItem): void
        {
            if (this._quickSellGoods && this._quickSellGoods.parent) 
            {
                this._quickSellGoods.updateQuickSellItem(arg1);
            }
            return;
        }

        public updateSeekBuyGoodsPanel(arg1: SSeqMarketItem): void
        {
            if (this._seekBuyGoods && this._seekBuyGoods.parent) 
            {
                this._seekBuyGoods.updateMaxPrice(arg1);
            }
            return;
        }

        public resetQuickSellGoodsPanel(): void
        {
            if (this._quickSellGoods && this._quickSellGoods.parent) 
            {
                this._quickSellGoods.resetPanel();
            }
            if (!SellGoodsTips.instance.isHide) 
            {
                SellGoodsTips.instance.hide();
            }
            return;
        }

        public getSeekBuySelectedIdx(): int
        {
            return this._tabBar.selectedIndex;
        }

        public /* override */ hide(): void
        {
            super.hide();
            this.hideSeekBuyItem();
            Dispatcher.dispatchEvent(new DataEvent(EventName.MarketSeekBuyWindowStateChange, false));
            return;
        }

        /* internal  */onItemsResultHandler(arg1: DataEvent): void
        {
            this._seekBuyItemPanel.updateList(arg1.data as Array<any>);
            return;
        }

        /* internal */ /* var */_tabBar: GTabBar;

        /* internal */ /* var */_quickSellGoods: QuickSellGoodsPanel;

        /* internal */ /* var */_selfGoods: SelfGoodsPanel;

        /* internal */ /* var */_seekBuyGoods: SeekBuyGoodsPanel;

        /* internal */ /* var */_seekBuyItemPanel: SeekBuyItemPanel;
    }
